package com.baihuabooks.scoresys.servlets;

import com.baihuabooks.scoresys.common.Config;
import com.baihuabooks.scoresys.common.DBUtil;
import com.baihuabooks.scoresys.common.Locale;
import com.mysql.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.beans.PropertyVetoException;

/**
 * Created by Thinkpad on 2016/5/17 0017.
 */
public class AppListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {
        Config.init();
        Locale.init();
        System.out.println("Config initialized.");
        try {
            DBUtil.getInstance().init();
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
        System.out.println("DB initialized.");
    }

    public void contextDestroyed(ServletContextEvent sce) {
        DBUtil.getInstance().destroy();
        try {
            AbandonedConnectionCleanupThread.shutdown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
